package com.ruoyi.web.controller.bargain;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bargain.domain.BargainRecord;
import com.ruoyi.bargain.service.IBargainRecordService;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.base.AjaxResult;

/**
 * 砍价帮砍记录 信息操作处理
 * 
 * @author lzy
 * @date 2019-03-07
 */
@Controller
@RequestMapping("/bargain/bargainRecord")
public class BargainRecordController extends BaseController
{
    private String prefix = "bargain/bargainRecord";
	
	@Autowired
	private IBargainRecordService bargainRecordService;
	
	@RequiresPermissions("bargain:bargainRecord:view")
	@GetMapping()
	public String bargainRecord()
	{
	    return prefix + "/bargainRecord";
	}
	
	/**
	 * 查询砍价帮砍记录列表
	 */
	@RequiresPermissions("bargain:bargainRecord:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(BargainRecord bargainRecord)
	{
		startPage();
        List<BargainRecord> list = bargainRecordService.selectBargainRecordList(bargainRecord);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出砍价帮砍记录列表
	 */
	@RequiresPermissions("bargain:bargainRecord:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BargainRecord bargainRecord)
    {
    	List<BargainRecord> list = bargainRecordService.selectBargainRecordList(bargainRecord);
        ExcelUtil<BargainRecord> util = new ExcelUtil<BargainRecord>(BargainRecord.class);
        return util.exportExcel(list, "bargainRecord");
    }
	
	/**
	 * 新增砍价帮砍记录
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存砍价帮砍记录
	 */
	@RequiresPermissions("bargain:bargainRecord:add")
	@Log(title = "砍价帮砍记录", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(BargainRecord bargainRecord)
	{		
		return toAjax(bargainRecordService.insertBargainRecord(bargainRecord));
	}

	/**
	 * 修改砍价帮砍记录
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		BargainRecord bargainRecord = bargainRecordService.selectBargainRecordById(id);
		mmap.put("bargainRecord", bargainRecord);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存砍价帮砍记录
	 */
	@RequiresPermissions("bargain:bargainRecord:edit")
	@Log(title = "砍价帮砍记录", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(BargainRecord bargainRecord)
	{		
		return toAjax(bargainRecordService.updateBargainRecord(bargainRecord));
	}
	
	/**
	 * 删除砍价帮砍记录
	 */
	@RequiresPermissions("bargain:bargainRecord:remove")
	@Log(title = "砍价帮砍记录", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(bargainRecordService.deleteBargainRecordByIds(ids));
	}
	
}
